package com.imay.live.view.custom;

import android.content.Context;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.imay.live.R;
import com.imay.live.activity.discovery.PasteActivity;
import com.imay.live.model.FeedModel;
import com.imay.live.utils.GlideUtil;
import com.imay.live.utils.ViewUtil;

import java.util.ArrayList;

/**
 * Created by liangzhenxiong on 2017/04/11 0011.
 */

public class PastseRelatvieLayout extends RelativeLayout {
    /**
     * 设置视图数据
     *
     */
    public void setModel(ArrayList<FeedModel> feedSuggestModels) {
        if (feedSuggestModels == null) {
            return;
        }
        ImageView iv_show_left = ViewUtil.findView(this, R.id.iv_show_left);
        if (iv_show_left != null) {
            if (feedSuggestModels.size() > 0) {
                GlideUtil.loadRectangleImage(iv_show_left,feedSuggestModels.get(0).getImgUrl(),R.dimen.size_4dp,R.drawable.shape_placeholder_2);
            }
        }
        ImageView iv_show_mid = ViewUtil.findView(this, R.id.iv_show_mid);
        if (iv_show_mid != null) {
            if (feedSuggestModels.size() > 1) {
                GlideUtil.loadRectangleImage(iv_show_mid,feedSuggestModels.get(1).getImgUrl(),R.dimen.size_4dp,R.drawable.shape_placeholder_2);
            }
        }
        ImageView iv_show_right = ViewUtil.findView(this, R.id.iv_show_right);

        if (iv_show_right != null) {
            if (feedSuggestModels.size() > 2) {
                GlideUtil.loadRectangleImage(iv_show_right,feedSuggestModels.get(2).getImgUrl(),R.dimen.size_4dp,R.drawable.shape_placeholder_2);
            }
        }
    }

    public PastseRelatvieLayout(Context context) {
        super(context);
        init(context);
    }

    public PastseRelatvieLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public PastseRelatvieLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context);
    }

    @RequiresApi(api = 21)
    public PastseRelatvieLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context);
    }

    void init(Context context) {
//        android:layout_height="52dp"
        View view = LayoutInflater.from(context).inflate(R.layout.item_discoverypaste_layout, this, true);
        LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.height = (int) getResources().getDimension(R.dimen.pasteview_height);
        view.setLayoutParams(params);
        setBackgroundColor(getResources().getColor(R.color.mine_bg_fb));
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                PasteActivity.start(getContext());
            }
        });
    }
}
